#!/bin/csh
#...........................................................................
#BSUB -a poe                    # use LSF poe elim
#BSUB -x                        # exclusive use of node (not_shared)
#BSUB -n 1                      # total tasks needed
#BSUB -R "span[ptile=16]"       # max number of tasks (MPI) per node
#BSUB -J NDG
#BSUB -o %J.runout              # output filename
#BSUB -e %J.runout              # error filename
#BSUB -W 01:00
#BSUB -P P93300642
##BSUB -q regular             # queue
#BSUB -q small                  # regular 

set echo 

# CAM5 orography 
# 
# /glade/p/cesm/cseg/inputdata/atm/cam/topo/USGS-gtopo30_1.9x2.5_remap_c050602.nc oro_ecmwf_T170.nc
#  
# cdo sp2gp -sp2sp,170 -gp2sp -remapcon,t170grid oro_cam5.nc oro_cam5_t170.nc


foreach yy (2012) 
###foreach mm (01 02 03 04 05 06 07 08 09 10 11 12) 
foreach mm (06 07 08 09 10 11 12) 
foreach dd (01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) 

setenv mpath /glade/p/rda/data/ds627.0/ei.oper.an.ml/${yy}${mm}
setenv tpath /glade/scratch/kaizhang/data/ndata/tmp
setenv ipath /glade/scratch/kaizhang/data/ndata/input
setenv opath /glade/scratch/kaizhang/data/ndata/output
setenv spath /glade/scratch/kaizhang/data/ndata/cam5nud

foreach hh (00 06 12 18) 

echo ''
echo ''
echo ${yy}${mm}${dd}${hh} 
echo ''
echo ''

#.............................................................................. 
# 3. Do vertical interpolation using cdo remapeta 
#.............................................................................. 

cat > loadit << EOF
 fna = "${tpath}/tmp${yy}${mm}${dd}${hh}_stps.nc" 
 fno = "${tpath}/tmp${yy}${mm}${dd}${hh}_z3.nc" 
EOF

 ncl ${spath}/make_z3.ncl 

 cdo remapcon,r144x96 ${tpath}/tmp${yy}${mm}${dd}${hh}_z3.nc ${opath}/z3_2x2.5_${yy}${mm}${dd}${hh}.nc 

end 

end 

cdo mergetime ${opath}/z3_2x2.5_${yy}${mm}????.nc ${opath}/z3_2x2.5_${yy}${mm}.nc 

rm -f         ${opath}/z3_2x2.5_${yy}${mm}????.nc 

end

end



